package com.yuanchu.marketing.controller;

import com.yuanchu.common.utils.PageResult;
import com.yuanchu.common.utils.R;
import com.yuanchu.common.validator.ValidationGroups;
import com.yuanchu.marketing.dto.RechargePlanParamsDto;
import com.yuanchu.marketing.entity.YoshopRechargePlanEntity;
import com.yuanchu.marketing.service.YoshopRechargePlanService;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-03-03 14:11
 */
@RestController
@RequestMapping("recharge/plan")
public class RechargePlanController {

    @Resource
    private YoshopRechargePlanService rechargePlanService;

    @ApiOperation(value = "/api/recharge/list", tags = "获取充值套餐列表")
    @GetMapping("list")
    public R queryRechargePlanList(@RequestParam("page") Integer page, @RequestParam(value = "search", required = false) String search) {
        PageResult<YoshopRechargePlanEntity> pageResult = rechargePlanService.queryRechargePlanList(page, search);
        return R.ok().putPage("data", pageResult);
    }

    //add
    @ApiOperation(value = "/api/recharge/add", tags = "添加充值套餐")
    @PostMapping("add")
    public R addRechargePlan(@RequestBody RechargePlanParamsDto params) {
        rechargePlanService.addRechargePlan(params);
        return R.ok();
    }
    // edit
    @ApiOperation(value = "/api/recharge/edit", tags = "编辑充值套餐")
    @PostMapping("edit")
    public R editRechargePlan(@RequestBody @Validated(ValidationGroups.Update.class) RechargePlanParamsDto params) {
        rechargePlanService.editRechargePlan(params);
        return R.ok();
    }

    // delete
    @ApiOperation(value = "/api/recharge/delete", tags = "删除充值套餐")
    @PostMapping("delete")
    public R deleteRechargePlan(@RequestBody @Validated(ValidationGroups.Delete.class) RechargePlanParamsDto params) {
        rechargePlanService.deleteRechargePlan(params.getPlanId());
        return R.ok();
    }
}
